package com.zues.thread.lock.variable_class;

/**
 * 测试final的不可变性
 * 查看字节码校验
 * @author zues
 * @date 3/18/2025 9:37 下午
 */
public class TestFinal {

    final static int A = 10;
    final static int B = Short.MAX_VALUE + 1;

    final int a = 20;

    final int b = Integer.MAX_VALUE;

    final void test1(){}


}

class UseFinal1 {
    public void test(){
        //加final，相当于复制一份变量放入当前对象中，不加final相当于引用
        //加final字节码：BIPUSH 10
        //不加final字节码：GETSTATIC com/zues/thread/lock/variable_class/TestFinal.A : I
        System.out.println(TestFinal.A);
        System.out.println(TestFinal.B);
        System.out.println(new TestFinal().a);
        System.out.println(new TestFinal().b);
        new TestFinal().test1();
    }

}


class UseFinal2 {
    public void test(){
        System.out.println(TestFinal.A);
    }
}





